package com.ydjk.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.ydjk.common.utils.DateUtils;
import com.ydjk.common.utils.UuidUtil;
import com.ydjk.common.utils.pageData.PageData;
import com.ydjk.domain.JkInterfaceMessage;
import com.ydjk.mapper.JkHospitalizationInfoMapper;
import com.ydjk.mapper.JkUserMapper;
import com.ydjk.service.IJkInterfaceMessageService;
import com.ydjk.service.IJkPushService;
import com.ydjk.service.JkMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ydjk.mapper.JkVideoTypeMapper;
import com.ydjk.domain.JkVideoType;
import com.ydjk.service.IJkVideoTypeService;

/**
 * 视频分类管理Service业务层处理
 *
 * @author ydjk
 * @date 2023-09-22
 */
@Service
public class JkVideoTypeServiceImpl implements IJkVideoTypeService
{
    @Autowired
    private JkVideoTypeMapper jkVideoTypeMapper;
    @Autowired
    private JkUserMapper jkUserMapper;
    @Autowired
    private JkHospitalizationInfoMapper jkHospitalizationInfoMapper;
    @Autowired
    private IJkPushService iJkPushService;
    @Autowired
    private JkMessageService jkMessageService;
    @Autowired
    private IJkInterfaceMessageService iJkInterfaceMessageService;
    /**
     * 查询视频分类管理
     *
     * @param id 视频分类管理主键
     * @return 视频分类管理
     */
    @Override
    public JkVideoType selectJkVideoTypeById(Long id)
    {
        return jkVideoTypeMapper.selectJkVideoTypeById(id);
    }

    /**
     * 查询视频分类管理列表
     *
     * @param jkVideoType 视频分类管理
     * @return 视频分类管理
     */
    @Override
    public List<JkVideoType> selectJkVideoTypeList(JkVideoType jkVideoType)
    {
        return jkVideoTypeMapper.selectJkVideoTypeList(jkVideoType);
    }

    /**
     * 新增视频分类管理
     *
     * @param jkVideoType 视频分类管理
     * @return 结果
     */
    @Override
    public int insertJkVideoType(JkVideoType jkVideoType)
    {
        jkVideoType.setCreateTime(DateUtils.getNowDate());
        return jkVideoTypeMapper.insertJkVideoType(jkVideoType);
    }

    /**
     * 修改视频分类管理
     *
     * @param jkVideoType 视频分类管理
     * @return 结果
     */
    @Override
    public int updateJkVideoType(JkVideoType jkVideoType)
    {
        jkVideoType.setUpdateTime(DateUtils.getNowDate());
        return jkVideoTypeMapper.updateJkVideoType(jkVideoType);
    }

    /**
     * 批量删除视频分类管理
     *
     * @param ids 需要删除的视频分类管理主键
     * @return 结果
     */
    @Override
    public int deleteJkVideoTypeByIds(Long[] ids)
    {
        return jkVideoTypeMapper.deleteJkVideoTypeByIds(ids);
    }

    /**
     * 删除视频分类管理信息
     *
     * @param id 视频分类管理主键
     * @return 结果
     */
    @Override
    public int deleteJkVideoTypeById(Long id)
    {
        return jkVideoTypeMapper.deleteJkVideoTypeById(id);
    }

    @Override
    public List<PageData> selectDemo(PageData dd) {
        return jkVideoTypeMapper.selectDemo(dd);
    }

    @Override
    public PageData isWhetherPerfect(PageData pageData) {


        return (PageData)jkUserMapper.isWhetherPerfect(pageData);
    }

    @Override
    public  List<PageData> isAdmission(PageData pageData) {
        return ( List<PageData>)jkHospitalizationInfoMapper.isAdmission(pageData);
    }

    @Override
    public void admissionInsert(PageData pageData) {
        pageData.put("id", UuidUtil.get32UUID());
        pageData.put("createTime",DateUtils.getTime());
        jkHospitalizationInfoMapper.admissionInsert(pageData);

        PageData paramsPush = new PageData();
        paramsPush.put("pushType","入院推送");

        List<PageData> templatelist = jkMessageService.selectJkPushTemplateList(paramsPush);
        PageData template=templatelist.get(0);
        PageData a1params = new PageData();
        a1params.put("openId", pageData.get("openId"));
        List<PageData> list = jkMessageService.selectHospitalizationList(a1params);
        PageData data=list.get(0);


        List<JkInterfaceMessage> allList = new ArrayList<>();
        String pushTemplateId = template.getString("id");//
        String openId = data.getString("openId");//
        String unionId = data.getString("unionId");//
        Long userId = Long.parseLong(data.get("userId")+"");//
        JkInterfaceMessage jkInterfaceMessage=new JkInterfaceMessage();
        jkInterfaceMessage.setCreateTime(DateUtils.getNowDate());
        jkInterfaceMessage.setPushTemplateId(pushTemplateId);
        jkInterfaceMessage.setTitle(template.getString("name"));
        jkInterfaceMessage.setUserId(userId);
        jkInterfaceMessage.setType("入院推送");
        jkInterfaceMessage.setOpenId(openId);
        jkInterfaceMessage.setUnionId(unionId);
        allList.add(jkInterfaceMessage);
        iJkInterfaceMessageService.addInterfaceMessageList(allList);
        iJkPushService.addWxAddMessage(allList);

    }

    @Override
    public void admissionUpdate(PageData pageData) {
        jkHospitalizationInfoMapper.admissionUpdate(pageData);
    }

    @Override
    public void userUpdata(PageData pageData) {
        jkUserMapper.userUpdata(pageData);
    }

    @Override
    public List<PageData> getAllAdmission(PageData pageData) {
        return ( List<PageData>)jkHospitalizationInfoMapper.getAllAdmission(pageData);
    }
}
